/*
 * Copyright 2009 SHOP.COM
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.shop.opensocial.mediated.shindig.factories;

import com.shop.opensocial.mediated.types.OAuthEntryMediator;
import org.apache.shindig.social.opensocial.oauth.OAuthEntry;
import java.util.Date;

/**
 * Factory for converting between Mediator type and Shindig type
 * 
 * @author Jordan Zimmerman
 */
public class OAuthEntryMediatorFactory extends GenericMediatorFactory<OAuthEntry, OAuthEntryMediator>
{
	public static final GenericMediatorFactoryBase<OAuthEntry, OAuthEntryMediator>		i = new OAuthEntryMediatorFactory();

	@Override
	protected OAuthEntry internalMake(OAuthEntryMediator c)
	{
		OAuthEntry o = new OAuthEntry();
		o.appId = c.getAppId();
		o.authorized = c.getAuthorized();
		o.callbackUrl = c.getCallbackUrl();
		o.consumerKey = c.getConsumerKey();
		o.container = c.getContainer();
		o.domain = c.getDomain();
		o.issueTime = c.getIssueTime();
		o.token = c.getToken();
		o.tokenSecret = c.getTokenSecret();
		o.type = fTypeMapper.from(c.getType());
		o.userId = c.getUserId();
		return o;
	}

	@Override
	protected OAuthEntryMediator internalUnmake(final OAuthEntry c)
	{
		return new OAuthEntryMediator()
		{
			@Override
			public String getAppId()
			{
				return c.appId;
			}

			@Override
			public String getCallbackUrl()
			{
				return c.callbackUrl;
			}

			@Override
			public String getUserId()
			{
				return c.userId;
			}

			@Override
			public String getToken()
			{
				return c.token;
			}

			@Override
			public String getTokenSecret()
			{
				return c.tokenSecret;
			}

			@Override
			public boolean getAuthorized()
			{
				return c.authorized;
			}

			@Override
			public String getConsumerKey()
			{
				return c.consumerKey;
			}

			@Override
			public Type getType()
			{
				return fTypeMapper.to(c.type);
			}

			@Override
			public Date getIssueTime()
			{
				return c.issueTime;
			}

			@Override
			public String getDomain()
			{
				return c.domain;
			}

			@Override
			public String getContainer()
			{
				return c.container;
			}
		};
	}

	private OAuthEntryMediatorFactory()
	{
	}

	private static final EnumMapper<OAuthEntry.Type, OAuthEntryMediator.Type>		fTypeMapper = new EnumMapper<OAuthEntry.Type, OAuthEntryMediator.Type>(OAuthEntry.Type.values(), OAuthEntryMediator.Type.values());
}
